const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const FORM = 'FORM';
const DELETE = 'DELETE';

const baseURL = 'https://www.tymyztc.com/api/';
const token = 'tymy';
function request(method, url, data){
    return new Promise(function(resolve, reject) {
        let header = {
            'content-type': 'application/json',
            'token':token
        };
        wx.request({
            url: baseURL + url,
            method: method,
            data: data,
            header: header,
            success(res){
                //console.log('12233',res)
                resolve(res);
                //请求成功
                // //判断状态码---errCode状态根据后端定义来判断
                // if (res.data.errCode == 0) {
                //     resolve(res);
                // } else {
                //     //其他异常
                //     reject('运行时错误,请稍后再试');
                // }
            },
            fail(err) {
                //请求失败
                reject(err)
            }
        })
    })
}
const API = {
    // getOpenid: (data) => request(GET, `jsapi/mini?jsCode=${data}`),
    // banner: (data) => request(GET, `banner`,data),
    get:(url,data)=>request(GET,url,data),
    post:(url,data)=>request(POST,url,data),
    put:(url,data)=>request(PUT,url,data),
    delete:(url,data)=>request(DELETE,url,data),
};
module.exports = {
    API: API
}